<template>
  <el-container id="container">

  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <div id="title">中小学教学质量信息采集及评估系统</div>

    <el-form-item prop="username" class="in">
      <i class="el-icon-user" style="font-size: 26px; color: #526cc4;"></i>
      <div style="display: inline-block; color: #526cc4;">|</div>
      <el-input v-model="ruleForm.username" style="width: 250px;" placeholder="请输入用户名"></el-input>
    </el-form-item>
    <el-form-item prop="password" class="in">
      <i class="el-icon-lock" style="font-size: 26px; color: #526cc4;"></i>
      <div style="display: inline-block; color: #526cc4;">|</div>
      <el-input v-model="ruleForm.password" style="width: 250px;" type="password" placeholder="请输入密码"></el-input>
    </el-form-item>
<!--    <el-select v-model="value" placeholder="请选择登录身份" class="in" style="width: 200px; color: white;margin-left: 125px;margin-bottom: 30px">-->
<!--      <el-option-->
<!--          v-for="item in options"-->
<!--          :key="item.value"-->
<!--          :label="item.label"-->
<!--          :value="item.value">-->
<!--      </el-option>-->
<!--    </el-select>-->
      <el-form-item label="选择身份">
        <el-radio-group v-model="ruleForm.resource" @change="changeRole">
          <el-radio label="学校"></el-radio>
          <el-radio label="专家"></el-radio>
          <el-radio label="管理员"></el-radio>
        </el-radio-group>
      </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')" style="margin-left: 20px">登录</el-button>
      <el-button @click="resetForm('ruleForm')" style="margin-left: 100px">重置</el-button>
    </el-form-item>
  </el-form>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      // options: [{
      //   value: '1',
      //   label: '学校账号登录'
      // }, {
      //   value: '2',
      //   label: '专家账号登录'
      // },
      //   {
      //     value: '3',
      //     label: '管理员账号登录'
      //   },
      // ],
      value: '',
      ruleForm: {
        username: '',
        password: '',
        resource: '',
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          // { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      // const _this=this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post("http://localhost:8081/user/"+this.value+"/login",this.ruleForm).then((res)=>{
            // _this.$message({
            //   message: '添加成功！',
            //   type: 'success'
            // });
            //添加成功后页面跳转
            console.log(this.value)
            if (res.data!=''){
              console.log(this.value)
              //将res.data转为字符串存入localstorage(access-admin为key 可以通过get获取到)
              if (this.value==="1"){
                console.log("come in value 1")
                console.log(res.data)
                localStorage.setItem('access-schooluser',JSON.stringify(res.data));
                this.$message({
                  message: '登录成功！',
                  type: 'success'
                });
                this.$router.push('/indexSchoolUser');
              }
              if (this.value==="2"){
                console.log("come in value 2")
                localStorage.setItem('access-expert',JSON.stringify(res.data));
                this.$message({
                  message: '登录成功！',
                  type: 'success'
                });
                this.$router.push('/indexExpert');
              }
              if (this.value==="3"){
                console.log("come in value 3")
                localStorage.setItem('access-admin',JSON.stringify(res.data));
                this.$message({
                  message: '登录成功！',
                  type: 'success'
                });
                // this.$router.push('/SchoolList');
                this.$router.push('/welcome3');

              }
              else {

              }

            }
            else {
              alert("用户名或密码错误");
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    changeRole(){
      if (this.ruleForm.resource==="管理员"){
        this.value="3"
      }
      if (this.ruleForm.resource==="学校"){
        this.value="1"
      }
      if (this.ruleForm.resource==="专家"){
        this.value="2"
      }

    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
created() {
  this.ruleForm.resource="学校";
  this.value="1"
  console.log(this.value)
  localStorage.removeItem('access-admin')
  localStorage.removeItem('access-schooluser')
  localStorage.removeItem('access-expert')
}
}
</script>
<style scoped>
#container{
  background: url("../assets/background.jpg");
  width: 100%;
  height: 100%;
  position: fixed;
  background-size: 100%,100%;

}


.demo-ruleForm{

  width: 470px;
  height: 450px;
  background-color: #102962;
  margin: 120px auto;
  padding-right: 20px
}
#title{
  width: 100%;
  font-size: 26px;
  color: white;
  text-align: center;
  margin: 70px 0 30px 0;
}
/deep/input::-webkit-input-placeholder {
  color: #93a9e3;
  /*font-size: 15px;*/
}
/deep/.el-input__inner{
  background-color: transparent !important;
  border-top-width: 0px;
  border-left-width: 0px;
  border-right-width: 0px;
  border-bottom-width: 0px;
  border-radius: 0;
}
.in{
  border-bottom: #526cc4 1px solid;
  margin-left: 60px;
}
.in:hover{
  border-bottom: white 1px solid;
}
i{
  margin-left: -80px;
  margin-right: 10px;
}


</style>
